# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>

pkgname=python-aiobotocore
_pkgname=aiobotocore
# https://github.com/aio-libs/aiobotocore/releases
pkgver=2.7.0
pkgrel=1
pkgdesc='asyncio support for botocore library using aiohttp'
arch=(any)
url='https://github.com/aio-libs/aiobotocore'
license=(Apache)
depends=(python python-aiohttp python-botocore python-wrapt python-aioitertools
         # detected by namcap but not listed in setup.py
         python-dateutil python-jmespath python-multidict python-urllib3)
makedepends=(python-build python-installer python-setuptools python-wheel)
checkdepends=(python-moto python-pytest python-pytest-asyncio python-dill
              # moto optdepends
              python-docker python-openapi-spec-validator python-yaml python-flask python-flask-cors)
source=("https://github.com/aio-libs/aiobotocore/archive/$pkgver/$pkgname-$pkgver.tar.gz"
        moto-4.1.7.diff)
sha256sums=('a9a6f215c06f826bdbd9af25ea697bef0c9861e64e226a96cad519ab1a5548e7'
            '06c2548e54067c15c192c48b72a29b04b987aa3b694e7676366e3cbc638df81f')

prepare() {
  cd $_pkgname-$pkgver

  patch -Np1 -i ../moto-4.1.7.diff

  # For pytest-asyncio >= 0.19
  # https://github.com/aio-libs/aiobotocore/issues/965
  echo asyncio_mode = auto >> pytest.ini
}

build() {
  cd $_pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_pkgname-$pkgver

  export PYTHONPATH="$PWD"
  # test_lambda uses moto.awslambda, which requires a running Docker service
  # See: https://github.com/spulec/moto/issues/3276
  # test_version checks lower and upper bounds for dependencies in setup.py,
  # and they are patched away in prepare()
  pytest -m moto tests \
      --ignore=tests/test_lambda.py \
      --ignore=tests/test_version.py
}

package() {
  cd $_pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
}
